﻿@model WebUI.Areas.Bots.Models.UsersMachinesSetting
@{
    Layout = MVC.Bots.Shared.Views._Main;
}
@section Title{@WebUI.Resources.UsersAndMachines}
@section PageName{@WebUI.Resources.UsersAndMachines}
<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        ToggleUsersDivs();
        ToggleMachinesDivs();
    });

    function ToggleUsersDivs() {
        if ($('#AllUsers').is(':checked')) {
            $('#userName').attr('disabled', true);
            $('#userName').val("");
        } else {
            $('#userName').removeAttr('disabled');
        }
    }


    function ToggleMachinesDivs() {
        if ($('#AllMachines').is(':checked')) {
            $('#machineName').attr('disabled', true);
            $('#machineName').val("");
        } else {
            $('#machineName').removeAttr('disabled');
        }
    }
</script>
@Html.ValidationSummary(false)
<div class="filter_bar">
    <h3>
        Users & Machines Setting</h3>
    @using (Ajax.BeginForm(MVC.Bots.UsersAndMachines.AddUser(), new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "users" }))
    {
        <div id="CertainUsersDiv">
            User
            <input id="userName" name="userName" type="text" />
            <input type="submit" name="button" value='@WebUI.Resources.Add' />
            <div id="users">
                @{Html.RenderPartial(MVC.Bots.UsersAndMachines.Views._users, Model.SelectedUsers);}
            </div>
        </div>
    }
    @using (Ajax.BeginForm(MVC.Bots.UsersAndMachines.AddMachine(), new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "machines" }))
    {
        <div id="CertainMachinesDiv">
            Machine<input id="machineName" name="machineName" type="text" />
            <input type="submit" name="button" value='@WebUI.Resources.Add' />
            <div id="machines">
                @{Html.RenderPartial(MVC.Bots.UsersAndMachines.Views._machines, Model.SelectedMachines);}
            </div>
        </div>
    }
    @using (Html.BeginForm(MVC.Bots.UsersAndMachines.Save()))
    {
        <div class="filter_bar">
            <h3>
                Users</h3>
            <span>Everyone</span>
            @Html.RadioButtonFor(model => model.IsAllUsers, true, new { @id = "AllUsers", @onchange = "ToggleUsersDivs();" })<br />
            Certain Users
            @Html.RadioButtonFor(model => model.IsAllUsers, false, new { @onchange = "ToggleUsersDivs();" })<br />
        </div>
        <div class="filter_bar">
            <h3>
                Machines</h3>
            <span>All Machines</span>
            @Html.RadioButtonFor(model => model.IsAllMachines, true, new { @id = "AllMachines", @onchange = "ToggleMachinesDivs();" })<br />
            <span>Certain Machines</span>
            @Html.RadioButtonFor(model => model.IsAllMachines, false, new { @onchange = "ToggleMachinesDivs();" })<br />
        </div>
   
        
        @Html.ActionLink(WebUI.Resources.Previous, MVC.Bots.Operations.Index(), new { @class = "prev btn" })
        <input type="submit" class="next btn" name="button" value='@WebUI.Resources.Next' />
    }
</div>
